/**
 * scence方法
 * */


//场景列表
function sceneList(){
    var formData = {
        start: pages.start,
        limit: pages.limit,
    };
    $.ajax({
        type: apis.sceneIndex.method,
        url: apis.sceneIndex.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                console.log(res.msg);
            }
            var h = sceneHtml(res.data);
            $('#boxList').html(h);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}
//拼接字符串
function sceneHtml(d){
    var h = '', i, vid, thumb, title;
    for (i = 0; i < d.length; i ++) {
        vid = d[i].id;
        thumb = d[i].thumb;
        title = d[i].title;
        h += '<div class="boxOne" style="width: ' + (cw * 0.5 - 2) + 'px; height: ' + (cw * 0.5 * 1.7) + 'px; background: #fff;" onclick="toCnt(' + vid + ');">';
        if (thumb == '') {
            h += '';
        } else {
            h += '<img src="/' + thumb + '" style="width: ' + (cw / 2 -2) + 'px; height: ' + (cw / 2 * 1.7) + 'px;"/>';
        }
        h += '<div class="menu" style="left: ' + (cw * 0.5 - 40) + 'px;">';
        h += '<div><img src="/h5/imgs/mpPlay.png"/></div>';
        h += '<div>0</div>';
        h += '</div>';
        h += '<div class="boxTitle">' + title + '</div>';
        h += '</div>';
    }
    return h;
}


//去内容列表
function toCnt(v){
    var p = '/h5/scene-cnt.html';
    p += '?scene_id=' + v;
    p += '&code=' + code;
    p += '&h5code=' + h5code;
    window.location.href = p;
}


//场景内容列表
function cntList(){
    var formData = {
        scene_id: scene_id,
    };
    $.ajax({
        type: apis.sceneCntIndex.method,
        url: apis.sceneCntIndex.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code != 0) {
                console.log(res.msg);
            }
            var h = cntHtml(res.data);
            $('#boxList').html(h);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}
//内容字符串
function cntHtml(d){
    if (d.length == 0) { return }
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<div class="cnt">';
        if (d[i].type == 1) {
            h += d[i].cnt;
        }
        else if (d[i].type == 2) {
            h += '<img src="/' + d[i].cnt + '" style="width: 100%;"/>';
        }
        else {
            h += '<video controls autoplay loop muted style="width: 100%; height: 100%;">';
            h += '<source type="video/mp4" src="/' + d[i].cnt + '"/>';
            h += '</video>';
        }
        h += '</div>';
    }
    return h;
}